package wnhz.com.business.freeshop.activity.fourthfree;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import wnhz.com.business.R;
import wnhz.com.business.base.BaseActivity;
import wnhz.com.business.impl.ActionBarClickListener;
import wnhz.com.business.uitls.CustomerKeyboard;
import wnhz.com.business.uitls.PasswordEditText;
import wnhz.com.business.uitls.dialog.CommonDialog;
import wnhz.com.business.view.TranslucentActionBar;
import wnhz.com.business.view.TranslucentActionBarW;

/**
 * 提现
 */
public class TiXianActivity extends BaseActivity implements View.OnClickListener,ActionBarClickListener {

    @BindView(R.id.actionbar)
    TranslucentActionBarW actionbar;
    @BindView(R.id.tv_bankname)
    TextView tvBankname;
    @BindView(R.id.tv_cardnum)
    TextView tvCardnum;
    @BindView(R.id.ll_addcard)
    LinearLayout llAddcard;
    @BindView(R.id.et_number)
    EditText etNumber;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.tv_allmoney)
    TextView tvAllmoney;
    @BindView(R.id.tv_makesure)
    TextView tvMakesure;
    @BindView(R.id.ll_message)
    LinearLayout llMessage;

    private CustomerKeyboard customerKeyboard;
    private PasswordEditText passwordEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ti_xian_f);
        ButterKnife.bind(this);

        actionbar.setData("提现", R.drawable.ic_left_back, null, 0, null, 0, this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //改变状态栏颜色
            this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            actionbar.setStatusBarHeight(getStatusBarHeight());
        }

        initview();

    }

    public static Intent createIntent(Context context) {
        Intent intent = new Intent(context, TiXianActivity.class);
        return intent;
    }

    private void initview()
    {

        tvAllmoney.setOnClickListener(this);
        llAddcard.setOnClickListener(this);

        if (tvBankname.equals("")||tvBankname==null)
        {
            llMessage.setVisibility(View.GONE);
        }else
            {
                llMessage.setVisibility(View.VISIBLE);
            }

        etNumber.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                    if (etNumber.getText().toString().equals("")||etNumber.getText().toString()==null
                            ||Double.valueOf(etNumber.getText().toString())<0){
                        MyToast("没有可提现金额");
                        tvMakesure.setTextColor(getResources().getColor(R.color.text51));
                        tvMakesure.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_circle_grayd));
                        tvMakesure.setOnClickListener(null);
                    }else
                        {
                            tvMakesure.setTextColor(getResources().getColor(R.color.white));
                            tvMakesure.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_circle_reds));
                            tvMakesure.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    String maoney = etNumber.getText().toString();
//                                    if (maoney.equals("")||maoney==null||Double.valueOf(maoney)<0)
//                                    {
//                                        MyToast("没有可提现的金额");
//
//                                    }else
//                                    {
                                        final CommonDialog.Builder builder = new CommonDialog.Builder(TiXianActivity.this).fullWidth().fromBottom()
                                                .setView(R.layout.dialog_customer_keyboard);
                                        builder.setOnClickListener(R.id.delete_dialog, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                builder.dismiss();
                                            }
                                        });
                                        builder.create().show();
                                        TextView tv_moneyd = (TextView)builder.getView(R.id.tv_moneyd);
                                        tv_moneyd.setText("提现金额"+maoney+"元");
                                        //自定义的数字键盘
                                        customerKeyboard = builder.getView(R.id.custom_key_board);
                                        customerKeyboard.setOnCustomerKeyboardClickListener(new CustomerKeyboard.CustomerKeyboardClickListener() {
                                            @Override
                                            public void click(String number) {
                                                //输入点击的数字
                                                passwordEditText.addPassword(number);
                                            }

                                            @Override
                                            public void delete() {
                                                //删除输入的数字
                                                passwordEditText.deleteLastPassword();
                                            }
                                        });
                                        //自定义的密码输入框
                                        passwordEditText =  builder.getView(R.id.password_edit_text);
                                        passwordEditText.setOnPasswordFullListener(new PasswordEditText.PasswordFullListener() {
                                            @Override
                                            public void passwordFull(String password) {
                                                //得到输入的密码
                                                Log.e("test0916","密码：   "+password);
                                            }
                                        });
//                                    }
                                }
                            });
                        }
            }
        });

    }

    @Override
    public void onLeftClick() {
        finish();

    }

    @Override
    public void onRightClick() {

    }

    @Override
    public void onEditTextClick() {

    }

    @OnClick({R.id.tv_allmoney, R.id.tv_makesure,R.id.ll_addcard})
    public void onViewClicked(View view) {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_allmoney:
                if (tvMoney.getText().toString().equals("")||tvMoney.getText().toString()==null)
                {
                    MyToast("没有余额");
                }else
                {
                    etNumber.setText(tvMoney.getText().toString());
                }

                break;
            //添加银行
            case R.id.ll_addcard:
                startActivity(CardChooseActivity.createIntent(this));
                break;
        }
    }
}
